package com.hzdesk.media.koreabatchmatvector.dao;

import android.content.Context;
import android.util.Log;

import com.hzdesk.media.koreabatchmatvector.bean.DeviceAttributeBean;
import com.hzdesk.media.koreabatchmatvector.bean.DeviceAttributeBeanDao;

import java.util.List;

/**
 * Created by Administrator on 2018/7/2.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class DeviceAttributeBeanDaoUtils {
    private static final String TAG = MemoryDaoUtils.class.getSimpleName();
    private DaoManager daoManager;

    public DeviceAttributeBeanDaoUtils(Context context) {
        daoManager = DaoManager.getInstance();
        daoManager.init(context);
    }

    /**
     * 要保证数据库只有一条数据
     * @desc 插入之前要清空数据再插入
     * */
    public boolean insertDeviceAttributeBean(DeviceAttributeBean bean){
        boolean flag = false;
        DeviceAttributeBeanDao dao = daoManager.getDaoSession().getDeviceAttributeBeanDao();
        try {
            dao.deleteAll();
            flag =  dao.insert(bean) == -1? false : true;
        } catch (Exception e) {
            Log.e(TAG, "insertDeviceAttributeBean: 插入之前要清空数据再插入 "+e );
        }
        return flag;
    }
    /**
     * @desc 查询设备信息
     * */
    public List<DeviceAttributeBean> equery(){
        DeviceAttributeBeanDao dao = daoManager.getDaoSession().getDeviceAttributeBeanDao();
        List<DeviceAttributeBean> user1s = null;
        try {
            user1s = dao.loadAll();
        } catch (Exception e) {

        }
        return user1s;
    }
}
